use std::io;
use std::path::PathBuf;

use aspect_ident::DeviceIdent;
use thiserror::Error;

/// General errors.
#[derive(Debug, Error)]
pub enum Error {
    #[error("device ident could not be found '{0}'")]
    UnknownDeviceIdent(DeviceIdent),

    #[error("tried to query equivocated device '{0}'")]
    DeviceEquivocated(DeviceIdent),

    #[error("no homeserver connected")]
    NoHomeserver,

    #[error("datastore: {0}")]
    Datastore(#[from] aspect_db_common::errors::Error),

    #[error("aspprotocol: {0}")]
    ProtocolClient(#[from] aspect_proto::AspClientError),

    #[error("io at {0:?}: {1}")]
    IoAt(PathBuf, io::Error),

    #[error("io: {0}")]
    Io(#[from] io::Error),

    #[error("serde parse {0}: {1}")]
    SerdeJson(&'static str, serde_json::Error),

    #[error("{0}")]
    Other(String),
}
